package day9.homework;
//编写一个程序，启动三个线程，三个线程的名称分别是 A，B，C；
//每个线程将自己的名称在屏幕上打印5遍，打印顺序是ABCABC…
public class PrintABC implements Runnable{
    int id;
    static int count;
    public PrintABC(int id){
        this.id = id;
    }
    public void run() {
        String name = Thread.currentThread().getName();
        while (true){
            if (count>=15) break;
            synchronized (PrintABC.class){
                if (count%3 == id){
                    System.out.print(name);
                    count++;
                    PrintABC.class.notifyAll();
                }
                try {
                    PrintABC.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        new Thread(new PrintABC(0),"A").start();
        new Thread(new PrintABC(1),"B").start();
        new Thread(new PrintABC(2),"C").start();
    }
}
